/*Joseph A. Coll
RCV AP Countervailing/Heterogeneous Check
7/23/2025*/

*Load data
use "G:\My Drive\Backup 08202022\Working Papers\RCV and AP\Data and Methods\RCV AP Data Cleaned.dta", clear
cd "G:\My Drive\Backup 08202022\Working Papers\RCV and AP\Tables and Figures RCV AP"

********************************************************************************	
********************************************************************************
********************************************************************************
**# Ideology
********************************************************************************
********************************************************************************
********************************************************************************	
fre conservativism

********************************************************************************	
********************************************************************************
********************************************************************************
**#Main Analyses and Figures
********************************************************************************
********************************************************************************
********************************************************************************	

********************************************************************************
*Does Treatment Affect Affective Polarization
********************************************************************************
*FT
	*Affective polarization 
	reg ap_ft_change i.treatment##c.conservativism
	estimates store ap_ft_change_hetero
	margins, dydx(treatment) at(conservativism=(1(1)7)) post 
	mplotoffset, ///
	ciopts(recast(rcap) msize(small)) ///
	scheme(plotplain) ///
	xscale(r(.75 4.25)) ///
	xlabel(,angle(25)) ///
	title("", size(medium)) ///
	ytitle("Affective Polarization {&Delta}") ///
	yline(0, lpattern(longdash) lcolor(black%60)) ///
	yscale(r(-.0325 .035)) ///
	ylabel(-.03(.01).03) ///
	legend(order(3 "RCV Compliment" 4 "RCV Compliment + Endorse") pos(6)) ///
	name(ap_ft_change_hetero, replace) 
	graph export ap_ft_change_hetero.png, replace
	
	*In group
	reg ap_ft_ip_change  i.treatment##c.conservativism
	estimates store ap_ft_ip_change_hetero
	margins, dydx(treatment) at(conservativism=(1(1)7)) post 
	mplotoffset, ///
	ciopts(recast(rcap) msize(small)) ///
	scheme(plotplain) ///
	xscale(r(.75 4.25)) ///
	xlabel(,angle(25)) ///
	title("", size(medium)) ///
	ytitle("In-Group Affect {&Delta}") ///
	yline(0, lpattern(longdash) lcolor(black%60)) ///
	yscale(r(-.0325 .035)) ///
	ylabel(-.03(.01).03) ///
	legend(order(3 "RCV Compliment" 4 "RCV Compliment + Endorse") pos(6)) ///
	name(ap_ft_ip_change_hetero, replace) 
	graph export ap_ft_ip_change_hetero.png, replace	
	
	*Outgroup
	reg ap_ft_op_change  i.treatment##c.conservativism 
	estimates store ap_ft_op_change_hetero
	margins, dydx(treatment) at(conservativism=(1(1)7)) post 
	mplotoffset, ///
	ciopts(recast(rcap) msize(small)) ///
	scheme(plotplain) ///
	xscale(r(.75 4.25)) ///
	xlabel(,angle(25)) ///
	title("", size(medium)) ///
	ytitle("Out-Group Affect {&Delta}") ///
	yline(0, lpattern(longdash) lcolor(black%60)) ///
	yscale(r(-.0325 .035)) ///
	ylabel(-.03(.01).03) ///
	legend(order(3 "RCV Compliment" 4 "RCV Compliment + Endorse") pos(6)) ///
	name(ap_ft_op_change_hetero, replace) 
	graph export ap_ft_op_change_hetero.png, replace	

	grc1leg ap_ft_change_hetero ap_ft_ip_change_hetero ap_ft_op_change_hetero, ///
	title() ycommon  ///
	name(ft_combined_hetero, replace)
	graph export ft_combined_hetero.png, replace 

*Traits
	*Affective polarization
	reg ap_traits_change i.treatment##c.conservativism
	estimates store ap_traits_change_hetero
	margins, dydx(treatment) at(conservativism=(1(1)7)) post 
	mplotoffset, ///
	ciopts(recast(rcap) msize(small)) ///
	scheme(plotplain) ///
	xscale(r(.75 4.25)) ///
	xlabel(,angle(25)) ///
	title("", size(medium)) ///
	ytitle("Affective Polarization {&Delta}") ///
	yline(0, lpattern(longdash) lcolor(black%60)) ///
	yscale(r(-.0325 .035)) ///
	ylabel(-.03(.01).03) ///
	legend(order(3 "RCV Compliment" 4 "RCV Compliment + Endorse") pos(6)) ///
	name(ap_traits_change_hetero, replace) 
	graph export ap_traits_change_hetero.png, replace
	
	*In group
	reg ap_traits_ip_change i.treatment##c.conservativism
	estimates store ap_traits_ip_change_hetero
	margins, dydx(treatment) at(conservativism=(1(1)7)) post 
	mplotoffset, ///
	ciopts(recast(rcap) msize(small)) ///
	scheme(plotplain) ///
	xscale(r(.75 4.25)) ///
	xlabel(,angle(25)) ///
	title("", size(medium)) ///
	ytitle("In-Group Affect {&Delta}") ///
	yline(0, lpattern(longdash) lcolor(black%60)) ///
	yscale(r(-.0325 .035)) ///
	ylabel(-.03(.01).03) ///
	legend(order(3 "RCV Compliment" 4 "RCV Compliment + Endorse") pos(6)) ///
	name(ap_traits_ip_change_hetero, replace) 
	graph export ap_traits_ip_change_hetero.png, replace
	
	*Out group
	reg ap_traits_op_change i.treatment##c.conservativism
	estimates store ap_traits_op_change_hetero
	margins, dydx(treatment) at(conservativism=(1(1)7)) post 
	mplotoffset, ///
	ciopts(recast(rcap) msize(small)) ///
	scheme(plotplain) ///
	xscale(r(.75 4.25)) ///
	xlabel(,angle(25)) ///
	title("", size(medium)) ///
	ytitle("Out-Group Affect {&Delta}") ///
	yline(0, lpattern(longdash) lcolor(black%60)) ///
	yscale(r(-.0325 .035)) ///
	ylabel(-.03(.01).03) ///
	legend(order(3 "RCV Compliment" 4 "RCV Compliment + Endorse") pos(6)) ///
	name(ap_traits_op_change_hetero, replace) 
	graph export ap_traits_op_change_hetero.png, replace
	
	grc1leg ap_traits_change_hetero ap_traits_ip_change_hetero ap_traits_op_change_hetero, ///
	title() ycommon  ///
	name(t_combined_hetero, replace)
	graph export t_combined_hetero.png, replace 


*Feeling Thermometer table
	esttab ap_ft_change_hetero ap_ft_ip_change_hetero ap_ft_op_change_hetero ///
	using apft_hetero.tex, replace ///
	cells(b(star fmt(3)) se(fmt(3) par) ) starlevels( * 0.05 ** 0.01 *** 0.001) ///
	label ///
	stat(r2 N, fmt(2 0) label("R$^2$" "\textit{N}")) ///
	nodepvars nobase noomitted interaction(" x ") ///
	drop() ///
	style(tex) compress ///
	title("Electoral System, Candidate Communication, and Change in Partisan Affect (Feeling Thermometer)\label{tab:apfthetero}") ///
	mlabel("Affective Polarization" "In-Group" "Out-Group") 
		
*Traits table
	esttab ap_traits_change_hetero ap_traits_ip_change_hetero ap_traits_op_change_hetero ///
	using apt_hetero.tex, replace ///
	cells(b(star fmt(3)) se(fmt(3) par) ) starlevels( * 0.05 ** 0.01 *** 0.001) ///
	label ///
	stat(r2 N, fmt(2 0) label("R$^2$" "\textit{N}")) ///
	nodepvars nobase noomitted interaction(" x ") ///
	drop() ///
	style(tex) compress ///
	title("Electoral System, Candidate Communication, and Change in Partisan Affect (Traits)\label{tab:apthetero}") ///
	mlabel("Affective Polarization" "In-Group" "Out-Group") 	
	
